<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Asm Labels (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="Asm Labels (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="Asm Labels (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Using-Assembly-Language-with-C.html" rel="up" title="Using Assembly Language with C">
<link href="Explicit-Register-Variables.html" rel="next" title="Explicit Register Variables">
<link href="Constraints.html" rel="prev" title="Constraints">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
kbd.key {font-style: normal}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="subsection-level-extent" id="Asm-Labels">
<div class="nav-panel">
<p>
Next: <a href="Explicit-Register-Variables.html" accesskey="n" rel="next">Variables in Specified Registers</a>, Previous: <a href="Constraints.html" accesskey="p" rel="prev">Constraints for <code class="code">asm</code> Operands</a>, Up: <a href="Using-Assembly-Language-with-C.html" accesskey="u" rel="up">How to Use Inline Assembly Language in C Code</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Controlling-Names-Used-in-Assembler-Code"><span>6.47.4 Controlling Names Used in Assembler Code<a class="copiable-link" href="#Controlling-Names-Used-in-Assembler-Code"> &para;</a></span></h4>
<a class="index-entry-id" id="index-assembler-names-for-identifiers"></a>
<a class="index-entry-id" id="index-names-used-in-assembler-code"></a>
<a class="index-entry-id" id="index-identifiers_002c-names-in-assembler-code"></a>

<p>You can specify the name to be used in the assembler code for a C
function or variable by writing the <code class="code">asm</code> (or <code class="code">__asm__</code>)
keyword after the declarator.
It is up to you to make sure that the assembler names you choose do not
conflict with any other assembler symbols, or reference registers.
</p>
<h4 class="subsubheading" id="Assembler-names-for-data"><span>Assembler names for data<a class="copiable-link" href="#Assembler-names-for-data"> &para;</a></span></h4>

<p>This sample shows how to specify the assembler name for data:
</p>
<div class="example smallexample">
<pre class="example-preformatted">int foo asm (&quot;myfoo&quot;) = 2;
</pre></div>

<p>This specifies that the name to be used for the variable <code class="code">foo</code> in
the assembler code should be &lsquo;<samp class="samp">myfoo</samp>&rsquo; rather than the usual
&lsquo;<samp class="samp">_foo</samp>&rsquo;.
</p>
<p>On systems where an underscore is normally prepended to the name of a C
variable, this feature allows you to define names for the
linker that do not start with an underscore.
</p>
<p>GCC does not support using this feature with a non-static local variable 
since such variables do not have assembler names.  If you are
trying to put the variable in a particular register, see 
<a class="ref" href="Explicit-Register-Variables.html">Variables in Specified Registers</a>.
</p>
<h4 class="subsubheading" id="Assembler-names-for-functions"><span>Assembler names for functions<a class="copiable-link" href="#Assembler-names-for-functions"> &para;</a></span></h4>

<p>To specify the assembler name for functions, write a declaration for the 
function before its definition and put <code class="code">asm</code> there, like this:
</p>
<div class="example smallexample">
<pre class="example-preformatted">int func (int x, int y) asm (&quot;MYFUNC&quot;);
     
int func (int x, int y)
{
   /* <span class="r">...</span> */
</pre></div>

<p>This specifies that the name to be used for the function <code class="code">func</code> in
the assembler code should be <code class="code">MYFUNC</code>.
</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Explicit-Register-Variables.html">Variables in Specified Registers</a>, Previous: <a href="Constraints.html">Constraints for <code class="code">asm</code> Operands</a>, Up: <a href="Using-Assembly-Language-with-C.html">How to Use Inline Assembly Language in C Code</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
